#include "dkglBuffer.h"
#include <stdexcept>

namespace DKGL
{
    namespace Buffer
    {
        BufferFloat3::BufferFloat3()
        {
            buffer = NULL;
            count = 0;
        }

        BufferFloat3::~BufferFloat3()
        {
            dealloc();
        }

        void BufferFloat3::set(size_t index, float x, float y, float z)
        {
            if (index >= count)
                throw std::runtime_error("");

            size_t base = index * 3;

            buffer[base + 0] = x;
            buffer[base + 1] = y;
            buffer[base + 2] = z;

        }

        void BufferFloat3::alloc(size_t c)
        {
            delete [] buffer;

            count = c;

            buffer = new float[count*3];
        }

        void BufferFloat3::dealloc()
        {
            delete [] buffer;
            buffer = NULL;

        }

        void* BufferFloat3::get(void)
        {
            return buffer;
        }


        BufferFloat2::BufferFloat2()
        {
            buffer = NULL;
            count = 0;
        }

        BufferFloat2::~BufferFloat2()
        {
            dealloc();
        }

        void BufferFloat2::set(size_t index, float u, float v)
        {
            if (index >= count)
                throw std::runtime_error("");

            size_t base = index * 2;

            buffer[base + 0] = u;
            buffer[base + 1] = v;

        }

        void BufferFloat2::alloc(size_t c)
        {
            delete [] buffer;

            count = c;

            buffer = new float[count*2];
        }

        void BufferFloat2::dealloc()
        {
            delete [] buffer;
            buffer = NULL;

        }

        void* BufferFloat2::get(void)
        {
            return buffer;
        }


    }
}